# -*- coding: utf-8 -*-
"""
__mktime__ = '2019/4/14'
__author__ = 'Just'
__filename__ = 'app'
JSONEncoder default序列重写
"""
from datetime import date
from flask import Flask as _Flask
from flask.json import JSONEncoder as _JSONEncoder


class JSONEncoder(_JSONEncoder):
    def default(self, o):
        if hasattr(o, 'keys') and hasattr(o, '__getitem__'):
            """类对象序列规则"""
            return dict(o)
        if isinstance(o, date):
            """date类型序列规则"""
            return o.strftime('%Y-%m-%d')
        print(type(o), ' 这个类型无法序列化 ')
        raise Exception()


class Flask(_Flask):
    json_encoder = JSONEncoder
